package com.imay.live.adapter.family;

import android.content.Context;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.imay.live.R;
import com.imay.live.helper.LevelHelper;
import com.imay.live.model.FamilyApplyUserInfo;
import com.imay.live.utils.GlideUtil;
import com.imay.base.util.SpannableStringUtils;
import com.imay.live.utils.TimeUtil;

/**
 * Created by Administrator on 2017/9/7 0007.
 */

public class FamilyAcceptAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {

    public final static int VIEWTYPE_LINEAR_CONTENT = 0x114;//推荐结果

    public FamilyAcceptAdapter() {
        super(null);
        addItemType(VIEWTYPE_LINEAR_CONTENT, R.layout.item_accept_family_user);
    }

    @Override
    protected void convert(BaseViewHolder helper, MultiItemEntity item) {
        if (item.getItemType() == VIEWTYPE_LINEAR_CONTENT) {
            FamilyApplyUserInfo userInfo = (FamilyApplyUserInfo) item;
            ImageView iv_family_accept_head_img = helper.getView(R.id.iv_family_accept_head_img);
            GlideUtil.loadCircleImage(iv_family_accept_head_img,userInfo.getImgHead(), R.mipmap.placeholder
                  );
            final ImageView iv_family_accept = helper.getView(R.id.iv_family_accept);
            if (userInfo.isSelect()) {
                iv_family_accept.setSelected(true);
            } else {
                iv_family_accept.setSelected(false);
            }
            helper.setImageResource(R.id.iv_family_accept_sex, LevelHelper.getSexResId(userInfo.getSex()));
            helper.setText(R.id.tv_family_accept_live_level, String.valueOf(userInfo.getLiveLevel()));
            helper.setText(R.id.tv_family_accept_user_level, String.valueOf(userInfo.getUserLevel()));
            helper.setBackgroundRes(R.id.tv_family_accept_live_level, LevelHelper.getUserLevelResId(userInfo.getUserLevel()));
            helper.setBackgroundRes(R.id.tv_family_accept_user_level, LevelHelper.getLiveLevelResId(userInfo.getLiveLevel()));
            helper.setText(R.id.tv_family_accept_name, userInfo.getNick());

            SpannableStringUtils.Builder builder = SpannableStringUtils.getBuilder("");
            addNormalText(mContext, builder, userInfo.getExplain());
            addTime(mContext, builder, userInfo.getCreateAt());
            helper.setText(R.id.tv_family_accept_content, builder.create());


            helper.addOnClickListener(R.id.iv_family_accept);
        }
    }

    private static void addNormalText(Context context, SpannableStringUtils.Builder builder, String text) {
        builder.append(text).setForegroundColor(context.getResources().getColor(R.color.text_20));
    }

    private static void addTime(Context context, SpannableStringUtils.Builder builder, long time) {
        builder.append(" " + TimeUtil.getFriendlyTime(time)).setForegroundColor(context.getResources().getColor(R.color.text_bc)).setProportion(0.8f);
    }
}
